<%--
    Document   : registration.jsp
    Created on : 10 27, 10, 4:49:23 PM
    Author     : CCS
--%>


<%@page import="java.security.MessageDigest"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="java.sql.*, DBConnection.*, UserPackage.*" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>

     
    </head>
    <body>
      
      <%
            String fName=null, mName=null, lName=null, email=null, username=null, password=null, retypepass=null;        
            boolean result, result3, result4;
            int j=0;
           
            username = request.getParameter("username");
            password = request.getParameter("password");
            retypepass=request.getParameter("retype");
            fName = request.getParameter("fName");
            mName = request.getParameter("mName");
            lName = request.getParameter("lName");
            //address = request.getParameter("Address");
            email = request.getParameter("eAdd");
            String hash = new Hasher().passHasher("password");
            
            inputChecker check = new inputChecker();
            if(check.stringCompare(username) && check.stringCompare(password) && check.stringCompare(fName) &&
               check.stringCompare(mName) && check.stringCompare(lName))                   
            { 
           // if(request.getParameter("username")!= null && request.getParameter("password")!= null && request.getParameter("retypepass")!=null && request.getParameter("fName")!= null && request.getParameter("mName")!= null && request.getParameter("lName")!= null && request.getParameter("email")!= null ){                                                          
           /* username = username.replaceAll("[^a-zA-Z0-9@._]", "");
            password = password.replaceAll("[^a-zA-Z0-9@._]", "");
            retypepass = retypepass.replaceAll("[^a-zA-Z0-9@._];", "");
            fName = fName.replaceAll("[^a-zA-Z0-9@._]", "");
            mName = mName.replaceAll("[^a-zA-Z0-9@._]", "");
            lName = lName.replaceAll("[^a-zA-Z0-9@._]", "");
            email = email.replaceAll("[^a-zA-Z0-9@._]", "");
            */
            
            User newUser = new User();

            //newUser.setAddress(address);
            newUser.setfName(fName);
            newUser.setmName(mName);
            newUser.setlName(lName);
            newUser.setEmail(email);
            newUser.setUsername(username);
            newUser.setPassword(password);
            newUser.setRetypepass(retypepass);
            newUser.setHash(hash);
            

            result = new UserManager().addUser(newUser);
              //result2 = new UserManager().addLogIn(newUser);
                       

           System.out.println(result);
           if(result == true){
               session.setAttribute("username", username);
                request.setAttribute("username", username);
                request.setAttribute("password", password);
                response.sendRedirect("userHomePage.jsp");
              }
          }
            
            else
              
              response.sendRedirect("home.jsp");
      %>
        
                  <%--     
            /* else
                response.sendRedirect("home.jsp");*/
            
            
            
           
             /* if(request.getParameter("username").length() < 6)
               {
                  out.println("Your username is too short");
                  out.println("<br>");
                  j++;
                 
                }

               if(request.getParameter("username").length() > 25)
               {
                  out.println("Your username is too long");
                  out.println("<br>");
                  j++;
                }

              if(request.getParameter("password").length() < 5)
               {
                  out.println("Your password is too short");
                  out.println("<br>");
                  j++;
                }

            if(!request.getParameter("password").equals(retypepass))
                {
                out.println("Your passwords do not match");
                  out.println("<br>");
                  j++;
                }

            if(request.getParameter("fName").contentEquals(""))
             {
                 out.println("You do not have a firstname");
                  out.println("<br>");
                  j++;

                }

                if(request.getParameter("lName").equals(""))
             {
                 out.println("You do not have a lastname");
                  out.println("<br>");
                  j++;

                }


             if(request.getParameter("email").equals(""))
             {
                 out.println("You do not have an email");
                  out.println("<br>");
                  j++;

                }

            
            result3= new UserManager().checkUser(request.getParameter("username"), request.getParameter("password"));
            
          

            if(result3 == true)
             {

                 out.println("Your username is taken");
                  out.println("<br>");
                  j++;


                }

              



          



  if(request.getParameter("email").indexOf("@")<1||request.getParameter("email").lastIndexOf(".")-request.getParameter("email").indexOf("@")<2)
    {
      out.println("Your email has the wrong format");
                  out.println("<br>");
      j++;
    }
            
           
        
           
             }
            else
            {
                response.sendRedirect("userHomePage.jsp");
                }
*/
          --%>
           </body>
</html>
